﻿
using System.Collections.Generic;
using System.Data;
using System;
namespace ZHDJ.MobileInterface
{
    public partial class GetPartyPhotoPicList : AbstractBasePage
    {
        protected override OutParam BusinessProcess<InParam, OutParam>(InParam inParam)
        {
            // 业务逻辑返回的响应对象  
            PartyPhotoPicOutParam result = new PartyPhotoPicOutParam();
            PartyPhotoPicInParam param = new PartyPhotoPicInParam();
            string logMsg = "";
            bool isFlag = true;
                 
            try
            {
                param = inParam as PartyPhotoPicInParam;
                if (string.IsNullOrEmpty(param.wall_id))
                {
                    result.code = "0";
                    result.desc = "留影墙ID不能为空";

                    isFlag = false;
                }

                if (param.page_no * param.page_count <= 0)
                {
                    result.code = "0";
                    result.desc = "当前页,以及页记录条数必须为大于0的正整数";

                    isFlag = false;
                } 

                if(isFlag)
                {
                    DataSet ds = InterfaceHelper.GetPartyPhotoPicList(param.wall_id, param.page_no, param.page_count);
                    if (ds != null && ds.Tables.Count == 2)
                    {
                        string temp = "";
                        PartyPhotoPic itemTemp;
                        result.data.total_pages = CommonUtils.GetTotalPages(Convert.ToInt32(ds.Tables[0].Rows[0][0]), param.page_count);
                        foreach (DataRow dr in ds.Tables[1].Rows)
                        {
                            itemTemp = new PartyPhotoPic(); 
                            itemTemp.comments = dr["comments"].ToString();
                            itemTemp.det_img = CommonUtils.GetFileUrl(dr["URL"].ToString()); 
                            itemTemp.name = dr["name"].ToString();
                            itemTemp.photo_id = dr["photo_id"].ToString();
                            itemTemp.thum_img = CommonUtils.GetSmallImg(CommonUtils.GetFileUrl(dr["URL"].ToString()));

                            //int index = itemTemp.thum_img.LastIndexOf(".");
                            //if (index > 0)
                            //{
                            //    temp = itemTemp.thum_img.Substring(0, index);
                            //    itemTemp.thum_img = itemTemp.thum_img.Replace(temp, temp + "_small");
                            //}

                            result.data.list.Add(itemTemp);
                        }
                    }  
                }
                logMsg = result.desc;
            }
            catch (Exception ex)
            {
                result.code = "0";
                result.desc = "操作异常，多次出现请联系管理员"; 
                logMsg = ex.Message + ":" + ex.StackTrace;
            }

            CommonUtils.InsertMobileInterfaceLog(SystemCode +"-GetPartyPhotoPicList", SerializeHelper.JsonSerializer<PartyPhotoPicInParam>(param), logMsg); 
            return result as OutParam;
        }

        protected void Page_Load(object sender, System.EventArgs e)
        {
            if (string.Compare(Request.QueryString["Safe"], "False", true) == 0)
                ProcessRequest<PartyPhotoPicInParam, PartyPhotoPicOutParam>();
            else
                SafeProcessRequest<PartyPhotoPicInParam, PartyPhotoPicOutParam>();
        }
    }

    #region 请求参数
    public class PartyPhotoPicInParam
    {
        /// <summary>
        /// 必填，	留影墙ＩＤ
        /// </summary>
        public string wall_id
        { get; set; } 

        /// <summary>
        /// 必填 当前页
        /// </summary>
        public int page_no
        { get; set; }

        /// <summary>
        /// 必填，每页记录条数
        /// </summary>
        public int page_count
        { get; set; }
    }
    #endregion

    #region 结果参数
    public class PartyPhotoPicOutParam
    {
        public PartyPhotoPicOutParam()
        {
            code = "1";
            desc = "操作成功";
            data = new PartyPhotoPicList();
        }

        /// <summary>
        /// 返回结果 具体见接口返回对照码 1	成功 0	失败 2	请求非法 加密结果和传入的MD5字符串进行比较，如果相同则执行接口操作，否则返回1001错误响应码
        /// </summary>
        public string code
        { get; set; }

        /// <summary>
        /// 结果描述 成功和失败都需要
        /// </summary>
        public string desc
        { get; set; }

        /// <summary>
        /// 留影墙照片列表
        /// </summary>
        public PartyPhotoPicList data
        { get; set; }
    }

    public class PartyPhotoPicList
    {
        public PartyPhotoPicList()
        {
            total_pages = 0;
            list = new List<PartyPhotoPic>();
        }

        public List<PartyPhotoPic> list { get; set; }

        /// <summary>
        /// 总页数
        /// </summary>
        public int total_pages
        { get; set; }
    }
     
    /// <summary>
    /// 留影墙照片
    /// </summary>
    public class PartyPhotoPic
    { 
        /// <summary>
        ///	照片ID		
        /// </summary>
        public string photo_id
        { get; set; } 

        /// <summary>
        ///	照片名称		
        /// </summary>
        public string name
        { get; set; } 

        /// <summary>
        ///	照片缩略图地址		
        /// </summary>
        public string thum_img
        { get; set; } 

        /// <summary>
        ///	照片详情大图地址		
        /// </summary>
        public string det_img
        { get; set; } 

        /// <summary>
        ///	评论数		
        /// </summary>
        public string comments
        { get; set; }  
    }
    #endregion 
}